package com.ukefu.webim.web.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;

import com.ukefu.core.UKDataContext;
import com.ukefu.util.UKTools;

@Entity
@Table(name = "uk_agentuser")
@Proxy(lazy = false)
public class AgentUser implements Serializable, Comparable<AgentUser> {
	private static final long serialVersionUID = -8657469468192323550L;
	private String id = UKTools.getUUID();
	private String username;
	private String agentno;
	private String userid;
	private String channel;
	private Date logindate;
	private String source;
	private Date endtime;
	
	private String creater ;	//原始 USERID
	
	private String endby ;	//挂断方
	
	private boolean refuse ;
	
	private String title ;
	private String url;
	private String traceid ;
	
	private String owner;	//变更用处，修改为 智能IVR的 EventID
	
	private String ipaddr;
	private String osname;
	private String browser;
	private String mobile;	//是否移动端
	private String nickname;
	protected String city;
	private String sessionid ;
	protected String province;
	protected String country;
	protected String headimgurl;
	private String region;
	private long sessiontimes = 0L;
	private int waittingtime;
	private int tokenum;			//坐席未读消息
	private int usernum;			//访客未读消息
	
	private Date createtime = new Date();
	private Date updatetime;
	private String status;
	private String appid;
	private String sessiontype;
	private Date queuetime ;								//进入队列的时间
	private String contextid = UKTools.getUUID();
	private String agentserviceid;
	private String orgi;
	private Date ordertime = new Date();
	private String snsuser;
	private Date lastmessage = new Date();
	private Date servicetime;
	private Date waittingtimestart = new Date();
	private Date lastgetmessage = new Date();
	private String lastmsg;
	
	private String skill ;	//请求的技能组
	private String agent ;	//请求的坐席
	
	private String skillname ;	//技能组名称
	
	private String name ;
	private String email ;
	private String phone ;
	private String resion ;
	
	private String membertype;//会员类型
	private String custype;//客户类型
	
	@Transient
	private boolean tip = false;
	@Transient
	private boolean agentTip = false;
	
	private boolean transfer;
	private Date transfertime;
	
	@Transient
	private String transferagent ;
	
	@Transient
	private String snsname;

	@Transient
	public boolean isAgentTip() {
		return this.agentTip;
	}

	public void setAgentTip(boolean agentTip) {
		this.agentTip = agentTip;
	}

	@Transient
	private boolean fromhis = false;
	@Transient
	private boolean online = false;
	@Transient
	private boolean disconnect = false;
	@Transient
	private String agentskill;
	private String agentservice;

	@Transient
	private Tenant tenant;

	@Transient
	public Tenant getTenant() {
		return tenant;
	}

	public void setTenant(Tenant tenant) {
		this.tenant = tenant;
	}

	private int invitevals;//邀请评价次数

	private String loginname;
	private String token;
	private String organ;

	public AgentUser() {
	}

	public AgentUser(String userid, String channel, String snsuser,
			String username, String orgi, String appid) {
		if(UKDataContext.ChannelTypeEnum.WEBIM.toString().equals(channel)) {
			this.userid = UKTools.getUniKey(userid, appid, orgi);
		}else {
			this.userid = userid ;
		}
		this.channel = channel;
		this.snsuser = snsuser;
		this.appid = appid;
		this.username = username;
		this.orgi = orgi;
		this.creater = userid ;
	}

	@Id
	@Column(length = 32)
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "assigned")
	public String getId() {
		return this.id;
	}

	public Date getCreatetime() {
		return this.createtime;
	}

	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}

	public Date getUpdatetime() {
		return this.updatetime;
	}

	public void setUpdatetime(Date updatetime) {
		this.updatetime = updatetime;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getUserid() {
		return this.userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public String getChannel() {
		return this.channel;
	}

	public void setChannel(String channel) {
		this.channel = channel;
	}

	public Date getLogindate() {
		return this.logindate;
	}

	public void setLogindate(Date logindate) {
		this.logindate = logindate;
	}

	public String getContextid() {
		return this.contextid;
	}

	public void setContextid(String contextid) {
		this.contextid = contextid;
	}

	public String getAgentno() {
		return this.agentno;
	}

	public void setAgentno(String agentno) {
		this.agentno = agentno;
	}

	public String getAgentserviceid() {
		return this.agentserviceid;
	}

	public void setAgentserviceid(String agentserviceid) {
		this.agentserviceid = agentserviceid;
	}

	public String getOrgi() {
		return this.orgi;
	}

	public void setOrgi(String orgi) {
		this.orgi = orgi;
	}

	public Date getLastmessage() {
		return this.lastmessage;
	}

	public void setLastmessage(Date lastmessage) {
		this.lastmessage = lastmessage;
	}

	@Transient
	public boolean isTip() {
		return this.tip;
	}

	public void setTip(boolean tip) {
		this.tip = tip;
	}

	@Transient
	public boolean isDisconnect() {
		return this.disconnect;
	}

	public void setDisconnect(boolean disconnect) {
		this.disconnect = disconnect;
	}

	public Date getEndtime() {
		return this.endtime;
	}

	public void setEndtime(Date endtime) {
		this.endtime = endtime;
	}

	public long getSessiontimes() {
		return this.sessiontimes;
	}

	public void setSessiontimes(long sessiontimes) {
		this.sessiontimes = sessiontimes;
	}

	@Transient
	public String getSessiontype() {
		return this.sessiontype;
	}

	public void setSessiontype(String sessiontype) {
		this.sessiontype = sessiontype;
	}

	public String getAgentskill() {
		return this.agentskill;
	}

	public void setAgentskill(String agentskill) {
		this.agentskill = agentskill;
	}

	@Transient
	public boolean isOnline() {
		return this.online;
	}

	public void setOnline(boolean online) {
		this.online = online;
	}

	@Transient
	public boolean isFromhis() {
		return this.fromhis;
	}

	public void setFromhis(boolean fromhis) {
		this.fromhis = fromhis;
	}

	public String getSource() {
		return this.source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public Date getLastgetmessage() {
		return this.lastgetmessage;
	}

	public void setLastgetmessage(Date lastgetmessage) {
		this.lastgetmessage = lastgetmessage;
	}

	public String getLastmsg() {
		return this.lastmsg;
	}

	public void setLastmsg(String lastmsg) {
		this.lastmsg = lastmsg;
	}

	public String getSnsuser() {
		return this.snsuser;
	}

	public void setSnsuser(String snsuser) {
		this.snsuser = snsuser;
	}

	public int getWaittingtime() {
		return this.waittingtime;
	}

	public void setWaittingtime(int waittingtime) {
		this.waittingtime = waittingtime;
	}

	public int getTokenum() {
		return this.tokenum;
	}

	public void setTokenum(int tokenum) {
		this.tokenum = tokenum;
	}

	public Date getWaittingtimestart() {
		return this.waittingtimestart;
	}

	public void setWaittingtimestart(Date waittingtimestart) {
		this.waittingtimestart = waittingtimestart;
	}

	public String getAppid() {
		return this.appid;
	}

	public void setAppid(String appid) {
		this.appid = appid;
	}

	public String getStatus() {
		return this.status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getCity() {
		return this.city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getProvince() {
		return this.province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getCountry() {
		return this.country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getHeadimgurl() {
		return this.headimgurl;
	}

	public void setHeadimgurl(String headimgurl) {
		this.headimgurl = headimgurl;
	}

	public String getNickname() {
		return this.nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getIpaddr() {
		return this.ipaddr;
	}

	public void setIpaddr(String ipaddr) {
		this.ipaddr = ipaddr;
	}

	public String getOsname() {
		return this.osname;
	}

	public void setOsname(String osname) {
		this.osname = osname;
	}

	public String getBrowser() {
		return this.browser;
	}

	public void setBrowser(String browser) {
		this.browser = browser;
	}

	@Transient
	public String getTopic() {
		return "/" + this.orgi + "/" + this.agentno;
	}

	public Date getOrdertime() {
		return ordertime;
	}

	public void setOrdertime(Date ordertime) {
		this.ordertime = ordertime;
	}

	public Date getServicetime() {
		return this.servicetime;
	}

	public void setServicetime(Date servicetime) {
		this.servicetime = servicetime;
	}

	public String getRegion() {
		return this.region;
	}

	public void setRegion(String region) {
		this.region = region;
	}

	public String getAgentservice() {
		return this.agentservice;
	}

	public void setAgentservice(String agentservice) {
		this.agentservice = agentservice;
	}
	public String getSkill() {
		return skill;
	}

	public void setSkill(String skill) {
		this.skill = skill;
	}

	public String getAgent() {
		return agent;
	}

	public void setAgent(String agent) {
		this.agent = agent;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getResion() {
		return resion;
	}

	public void setResion(String resion) {
		this.resion = resion;
	}
	
	public String getSessionid() {
		return sessionid;
	}

	public void setSessionid(String sessionid) {
		this.sessionid = sessionid;
	}
	
	public String getTitle() {
		return !StringUtils.isBlank(title) && title.length()>255 ? title.substring( 0 , 255) : title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getTraceid() {
		return traceid;
	}

	public void setTraceid(String traceid) {
		this.traceid = traceid;
	}
	public String getOwner() {
		return owner;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}
	
	public Date getQueuetime() {
		return queuetime;
	}

	public void setQueuetime(Date queuetime) {
		this.queuetime = queuetime;
	}
	
	public String getEndby() {
		return endby;
	}

	public void setEndby(String endby) {
		this.endby = endby;
	}

	@Transient
	public String getSkillname() {
		return skillname;
	}

	public void setSkillname(String skillname) {
		this.skillname = skillname;
	}
	@Transient
	public String getSnsname() {
		return snsname;
	}
	public void setSnsname(String snsname) {
		this.snsname = snsname;
	}
	public boolean isTransfer() {
		return transfer;
	}

	public void setTransfer(boolean transfer) {
		this.transfer = transfer;
	}
	@Transient
	public String getTransferagent() {
		return transferagent;
	}

	public void setTransferagent(String transferagent) {
		this.transferagent = transferagent;
	}
	public Date getTransfertime() {
		return transfertime;
	}

	public void setTransfertime(Date transfertime) {
		this.transfertime = transfertime;
	}
	@Transient
	public boolean isRefuse() {
		return refuse;
	}

	public void setRefuse(boolean refuse) {
		this.refuse = refuse;
	}

	@Override
	public int compareTo(AgentUser o) {
		int ret = 0 ;
		if(this.getLogindate() == null){
			ret = -1 ;
		}else if(o.getLogindate() == null){
			ret = 1 ;
		}else{
			if(this.getLogindate().after(o.getLogindate())){
				ret = 1 ;
			}else{
				ret = -1 ;
			}
		}
		return ret;
	}

	public int getInvitevals() {
		return invitevals;
	}

	public void setInvitevals(int invitevals) {
		this.invitevals = invitevals;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getCreater() {
		return creater;
	}

	public void setCreater(String creater) {
		this.creater = creater;
	}

	public int getUsernum() {
		return usernum;
	}

	public void setUsernum(int usernum) {
		this.usernum = usernum;
	}

	public String getMembertype() {
		return membertype;
	}

	public void setMembertype(String membertype) {
		this.membertype = membertype;
	}

	public String getCustype() {
		return custype;
	}

	public void setCustype(String custype) {
		this.custype = custype;
	}

	public String getLoginname() {
		return loginname;
	}

	public void setLoginname(String loginname) {
		this.loginname = loginname;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public String getOrgan() {
		return organ;
	}

	public void setOrgan(String organ) {
		this.organ = organ;
	}
}
